package com.io;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.io.*;

@AllArgsConstructor
@NoArgsConstructor
@ToString
@Data

class User implements Externalizable {

    private String name;
    private Integer age;

    @Override
    public void writeExternal(ObjectOutput out) throws IOException {
        out.writeUTF("姓名"+this.name);
        out.writeChar('\t');
        out.writeInt(this.age);
    }

    @Override
    public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
        this.name = in.readUTF();
        in.readChar();
        this.age=in.readInt()+1000;
    }
}

public class ObjectOutputStreamDemo01 {

    public static void main(String[] args) throws IOException {
        ObjectOutputStream objectOutputStream = new ObjectOutputStream(new FileOutputStream("D:\\dev\\1\\oout.txt"));
        User user = new User("zhangsa", 20);
        objectOutputStream.writeObject(user);
        objectOutputStream.close();
    }


}
